import { useEffect, useState } from 'react'
import { Navigate } from 'react-router-dom'

const Auth = ({ children }) => {
  const [isLogin, setIsLogin] = useState(true)
  useEffect(() => {
    const token = localStorage.getItem('dr_id')
    setIsLogin(!!token)
  }, [])
  if(isLogin) { 
    return children
  } else { 
    return <Navigate to="/login" replace />
  }
}

export default Auth  